<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="misc.Configurations"%>
<%@page import="java.io.*"%>
<%@page import="org.apache.commons.fileupload.servlet.*"%>
<%@page import="org.apache.commons.fileupload.*"%>
<%@page import="org.apache.commons.fileupload.disk.*"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><%=Configurations.title%>Upload</title>
</head>
<body>
<h1>Upload a file</h1>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart)
{
	// Create a factory for disk-based file items
	DiskFileItemFactory factory = new DiskFileItemFactory();

	// Set factory constraints
	//factory.setSizeThreshold(1024);

	// Create a new file upload handler
	ServletFileUpload upload = new ServletFileUpload(factory);

	// Set overall request size constraint
	//upload.setSizeMax(yourMaxRequestSize);

	// Parse the request
	List /* FileItem */ items = upload.parseRequest(request);
	
	// Process the uploaded items
	Iterator iter = items.iterator();
	while (iter.hasNext()) {
	    FileItem item = (FileItem) iter.next();

	    // Process a file upload
	    if (!item.isFormField()) {
	        String fieldName = item.getFieldName();
	        String fileName = item.getName();
	        String contentType = item.getContentType();
	        boolean isInMemory = item.isInMemory();
	        long sizeInBytes = item.getSize();
	        
	        File file = new File(Configurations.StorageDir+"test.dat");
            item.write(file);
            
            System.out.println("Is in memory? "+isInMemory);
	    }
	}
}
%>
<form ENCTYPE="multipart/form-data" action="Upload.jsp" method="post">
    <table border="0">
        <tr>
          <td>File</td><td><input type="file" size="40" name="filepath"/></td>
        </tr>
        <tr>
          <td colspan="2" align="right"><input type="submit" value="Upload"/></td>
        </tr>
    </table>
</form>
<small>Note: Anonymous users can only upload files of up to 1MB and keep for 60 minutes.</small>
</body>
</html>